# -*- coding: utf-8 -*-

from django.db import models
from core.models import CoreModel, table_prefix
from django.utils.translation import gettext_lazy as _
import reversion


@reversion.register()
class TestReport(CoreModel):
    name = models.CharField(max_length=256, verbose_name="报告名称")
    product = models.ForeignKey(
        to="pms.Product",
        related_name="testreport_set",
        on_delete=models.CASCADE,
        db_constraint=False,
        verbose_name="所属产品",
    )
    owner = models.ForeignKey(
        to="sys.User",
        related_name="testreport_owner_set",
        on_delete=models.DO_NOTHING,
        db_constraint=False,
        verbose_name="负责人",
    )
    participants = models.ManyToManyField(
        to="sys.User",
        related_name="testreport_participants_set",
        db_constraint=False,
        verbose_name="参与人",
    )
    testplan = models.ForeignKey(
        to="TestPlan",
        related_name="testreport_set",
        on_delete=models.DO_NOTHING,
        db_constraint=False,
        verbose_name="测试计划",
    )
    start_time = models.DateTimeField(null=True, blank=True, verbose_name="开始时间")
    end_time = models.DateTimeField(null=True, blank=True, verbose_name="结束时间")

    def __str__(self) -> str:
        return self.name

    class Meta:
        db_table = table_prefix + "tms_testreport"
        verbose_name = "测试报告"
        verbose_name_plural = verbose_name
        ordering = ("-create_time",)
